package Syntax;

import java.util.ArrayList;


public class Production {
    private String left;
    private ArrayList<Symbol> right = new ArrayList<Symbol>();

    public Production(){}
    public Production(String left, ArrayList<Symbol> right) {
        this.left = left;
        this.right = right;
    }

    public Production(Production new_Prod)
    {
        this.left = new_Prod.getLeft();
        this.right.addAll( new_Prod.getRight() );
    }

    public String getLeft() {
        return left;
    }

    public void setLeft(String left) {
        this.left = left;
    }

    public ArrayList<Symbol> getRight() {
        return right;
    }

    public void setRight(ArrayList<Symbol> right) {
        this.right = right;
    }

    public void addRightSymbol( Symbol sym ) {
        this.right.add( sym );
    }

    public boolean equals(Object obj)
    {
        if(obj instanceof  Production)
        {
            Production p = (Production)obj;
            if( p.getLeft().equals(this.left) && this.listEquals(p.getRight(), this.right) )
                return true;
        }
        return false;
    }

    public static boolean listEquals(ArrayList<Symbol> list1, ArrayList<Symbol> list2 )
    {
        if( list1.size() != list2.size() )
            return false;
        for(int i=0; i<list1.size(); i++)
        {
            if( !list1.get(i).equals( list2.get(i) ) )
                return false;
        }
        return true;
    }

    public int hashCode()
    {
        return this.left.hashCode() + right.size()*100;
    }
}
